/**
* @Description: WoShop商城
* @Author: 梧桐
* @Copyright: 武汉一一零七科技有限公司©版权所有
* @Link: www.wo-shop.net
* @Contact: QQ:2487937004
*/
<template>
	<view class="index_class">
		<view class="refun-type">
			<image :src="orgoods.thumb_url" />
			<view class="refun-text">
				<view style="color:#333">{{orgoods.goods_name}}</view>
				<text>{{orgoods.goods_attr_str}}</text>
				<text class="color">￥{{orgoods.price}} x {{orgoods.goods_num}}</text>
			</view>
		</view>

		<view class="lication-list" @tap="actionSheetTap" v-if="orgObj.th_cate == 1 && orgObj.tui_canshu == 0">
			<view>{{$t('收货状态')}}</view>
			<view class="right-text">
				{{listcheck[tapIndex]}}
				<i class="iconfont icon_e60c"></i>
			</view>
		</view>

		<view class="lication-list" v-if="orgObj.th_cate == 1 && orgObj.tui_canshu == 0">
			<view>{{$t('退款原因')}}</view>
			<view class="right-text" @click="checklist">
				{{remess? remess: $t('请选择原因')}}
				<i class="iconfont icon_e60c"></i>
			</view>
		</view>

		<view class="lication-list" @click="getnav('/pagesB/my/address?isconfirm=true')" v-if="orgObj.th_cate == 3">
			<view>{{$t('换货地址')}}</view>
			<view style="flex:1;padding-left:35rpx;color:#999">
				<view>{{address.contacts}} &nbsp;&nbsp; {{address.phone?address.phone: ''}}</view>
				<view>{{address.pro_name}}{{address.city_name}}{{address.area_name}} {{address.address}}</view>
			</view>

			<i class="iconfont icon_e60c"></i>
		</view>

		<view class="lication-list" v-if="orgObj.th_cate != 1 || orgObj.tui_canshu == 1">
			<view>{{orgObj.th_cate == 2 ? $t('退货原因'): $t('换货原因')}}</view>
			<view class="right-text" @click="hidePopup">
				{{remess? remess: $t('请选择原因')}}
				<i class="iconfont icon_e60c"></i>
			</view>
		</view>

		<view class="lication-list" v-if="orgObj.th_cate == 1 || orgObj.th_cate == 2">
			<view>
				{{$t('退款金额')}}
				<text style="color:#FA3F3F;padding-left:30upx;">￥{{orgoods.tui_price}}</text>
			</view>
			<view class="right-text"></view>
		</view>
		<!-- <view style="padding:16upx 30upx;font-szie:26upx;color:#999">最多¥19.00 含发货邮费¥0.00</view> -->
		<view class="lication-list">
			<view>{{orgObj.th_cate == 3? $t('换货说明') : $t('退款说明')}}</view>

			<!-- <view class="right-text"></view> -->
			<input style="flex:1;padding-left:30upx;" type="text" v-model="shou" :placeholder="$t('选填')" />
		</view>

		<view class="voucher">
			<view>
				{{$t('上传凭证')}}
			</view>
			<u-upload :action="upLoadAction" :form-data="formData" ref="uUpload" max-count="3" on-success="onUploaded">
			</u-upload>
		</view>

		<view class="person-button" style="margin:0;background-color:#fff;padding-top:40upx">
			<button type="warn" class="btn" @click="getaddthorder">{{$t('提交审核')}}</button>
		</view>

		<popup-layer ref="popupRef" :direction="'top'">
			<view class="checkal">
				<view class="check-title">{{$t('请选择原因')}}</view>

				<view class="check-cont">
					<view class="check-list" v-for="(item,index) in orgObj.thmessres" :key="index"
						@click="getCheck(item.id)">
						{{item.mess}}
						<!-- :class="cart.icon ? 'icon_e632' :'icon_e741'" -->
						<i class="iconfont icon_e741" :class="item.icon?'icon_e632' :'icon_e741'"></i>
					</view>
				</view>
			</view>
		</popup-layer>
	</view>
</template>

<script>
	let thObj = {};
	let reasonid = ""; // 退款原因id
	export default {
		data() {
			return {
				orgoods: "",
				tapIndex: 0,
				orgObj: "",
				imgPath: [],
				address: "",
				shou: "",
				remess: "", // 退款原因
				listcheck: [this.$t('请选择'), this.$t('未收货'), this.$t('已收货')],
				valueStatus: 0,
				upLoadAction: '',
				formData: {}
			};
		},
		onLoad(option) {
			if (option) {
				thObj = option;
				let tabtitle = "";
				if (option.th_cate == 3) {
					tabtitle = this.$t('申请换货');
				} else if (option.th_cate == 2) {
					tabtitle = this.$t('申请退货退款');
				} else {
					tabtitle = this.$t('申请退款');
				}
				uni.setNavigationBarTitle({
					title: tabtitle
				});
				this.getthindex(thObj);
			}
			const apiUrl = 'api/Common/uploadPic'
			const baseUrl = uni.getStorageSync('baseUrl');
			this.upLoadAction = `${baseUrl}${apiUrl}`
			this.formData = this.$http.returnCommonParams(apiUrl, 'product_return')
			console.log(this.upLoadAction)
		},
		onShow() {
			if (this.$store.state.confirmAddress) {
				this.address = this.$store.state.confirmAddress;
			}
		},

		watch: {
			tapIndex() {
				if (this.tapIndex == 0) {
					return false;
				}
				this.$http.getreason({
					sh_type: this.tapIndex
				}).then(res => {
					if (res.status == 200) {
						this.orgObj.thmessres = res.data.reason;
						console.log(this.orgObj.thmessres);
					}
				});
			}
		},
		methods: {
			// 获取图片上传列表
			getUpLoadImgList() {
				let files = [];
				// 通过filter，筛选出上传进度为100的文件(因为某些上传失败的文件，进度值不为100，这个是可选的操作)
				files = this.$refs.uUpload.lists.filter(val => {
					return val.progress == 100;
				})
				return files.map(res => res.response.data.path) || []
			},
			/**
			 * 提交审核
			 */
			getaddthorder() {
				if (!this.getUpLoadImgList().length) {
					return this.$toast("请上传凭证");
				}
				if (this.orgObj.th_cate == 1 && this.orgObj.tui_canshu == 0) {
					if (this.tapIndex == 0) {
						this.$toast(this.$t('请先选择收货状态'));
						return false;
					}
				}

				if (reasonid == "") {
					this.$toast(this.$t('请选择退款原因'));
					return false;
				}
				let data = {
					order_num: this.orgoods.ordernumber,
					orgoods_id: this.orgoods.id,
					th_cate: this.orgObj.th_cate,
					sh_type: this.tapIndex,
					reason_id: reasonid,
					dz_id: this.address.id,
					th_content: this.shou,
					imageres: this.getUpLoadImgList()
				};

				if (this.orgObj.tui_canshu == 1) {
					data.tui_canshu = this.orgObj.tui_canshu;
				}

		 
					this.$loading();
					this.$http.getaddthorder(data).then(res => {
						if (res.status == 200) {
							this.$toast(res.mess);
							setTimeout(() => {
								
								uni.redirectTo({
									url: "/pagesC/order/refundList"
								});
							}, 1000);
						} else {
							this.$toast(res.mess);
						}
					});
					return false;
				 

				this.$loading();
				// this.$http
				// 	.getpersonapply(data, "api/ThApply/addthorder")
				// 	.then(res => {
				// 		res = JSON.parse(res);
				// 		if (res.status == 200) {
				// 			this.$toast(res.mess);
				// 			setTimeout(() => {
				// 				// this.getback()
				// 				uni.redirectTo({
				// 					url: "/pagesC/order/refundCopy?order_id=" +
				// 						this.orgoods.order_id +
				// 						"&orgoods_id=" +
				// 						this.orgoods.id
				// 				});
				// 			}, 1000);
				// 		} else {
				// 			this.$toast(res.mess);
				// 		}
				// 	});
			},

			checklist() {
				if (this.tapIndex == 0) {
					this.$toast(this.$t('请先选择收货状态'));
					return false;
				}
				this.$refs.popupRef.show(); // 弹出
			},
			hidePopup() {
				this.$refs.popupRef.show(); // 弹出
			},
			getthindex(data) {
				this.$http.getthindex(data).then(res => {
					if (res.status == 200) {
						res.data.thmessres.forEach(element => {
							element.icon = false;
						});
						this.orgoods = res.data.orgoods;
						this.orgObj = res.data;
						if (res.data.th_cate == 3) {
							this.address = res.data.dizhis;
						}
					}
				});
			},
			actionSheetTap() {
				uni.showActionSheet({
					itemList: this.listcheck,
					success: e => {
						this.tapIndex = e.tapIndex;
					}
				});
			},
			getCheck(id) {
				this.orgObj.thmessres.forEach(element => {
					element.icon = false;
					if (element.id == id) {
						element.icon = true;
						reasonid = element.id;
						this.remess = element.mess;
						this.statusMath(this);
					}
				});
			},
		}
	};
</script>

<style>
	.checkal {
		height: 500upx;
		position: relative;
	}

	.check-cont {
		height: calc(100% - 90upx);
		overflow-y: auto;
	}

	.icon_e712 {
		text-align: center;
		font-size: 45upx;
	}
</style>
